using UnityEngine;
using System.Collections;

/// <summary>
/// Pathpair stores two object of IPath, whose anchors are identical the same,
/// but with inverse order. Say a line from anchor A to anchor B, then we can
/// build a line from B to A, then store these two lines into a PathPair.
/// </summary>
public class PathPair : IPath
{
	public PathPair (IPath rawPath)
	{
		m_rawPath = rawPath;
		m_inversedPath = rawPath.inversedPath;
	}
	
	/// <summary>
	/// Anchor is used to control tagent and length of a path,
	/// for example, a line has two anchors positioned at two 
	/// end-poins of the line, and a 5-th bezier curve has six
	/// anchors.
	/// </summary>
	public void SetAnchor (int index, Vector3 anchor)
	{
		m_rawPath.SetAnchor (index, anchor);
		m_inversedPath.SetAnchor (m_inversedPath.anchorCount - index - 1, anchor);
	}
	
	/// <summary>
	/// Gets anchor.
	/// </summary>
	public Vector3 GetAnchor (int index)
	{
		return m_rawPath.GetAnchor (index);
	}
	
	/// <summary>
	/// Sample current path using successive lines, large sampleTimes
	/// could led a more smooth appearence than a small sampleTimes
	/// </summary>
	public void Sample (int sampleTimes)
	{
		m_rawPath.Sample (sampleTimes);
		m_inversedPath.Sample (sampleTimes);
	}
	
	/// <summary>
	/// Gets a point on this path, of which y compnent is always zero.
	/// The returned point will not be exactly on this path for most of
	/// the time, but somewhere between two sampled points of the path, 
	/// S1 and S2, where sampled length of this curve before S1 is samller 
	/// than length and sampled length of this curve before S2 is larger 
	/// than length.
	/// </summary>
	public Vector3 GetXZPointOnCurve (float length, out Vector3 tagentXZ)
	{
		return m_rawPath.GetXZPointOnCurve (length, out tagentXZ);
	}
	
	/// <summary>
	/// Get point on the curve with t, which is used in the underline
	/// parametric equation and should always between 0 and 1.
	/// </summary>
	public Vector3 Solve (float t)
	{
		return m_rawPath.Solve (t);
	}
	
	/// <summary>
	/// Render this path in editor mode. Call this method in OnDrawGizmos.
	/// </summary>
	public void Render ()
	{
		m_rawPath.Render ();
	}
	
	/// <summary>
	/// Gets the number of anchors of this path.
	/// </summary>
	public int anchorCount 
	{ 
		get
		{ 
			return m_rawPath.anchorCount; 
		} 
	}
	
	/// <summary>
	/// Gets the sampled length of this path.
	/// </summary>
	public float sampledLength 
	{
		get
		{
			return m_rawPath.sampledLength;
		}
	}
	
	/// <summary>
	/// Inversed path shares the same anchor with this one, but inversed
	/// anchor order.
	/// </summary>
	public IPath inversedPath 
	{ 
		get 
		{ 
			return m_inversedPath; 
		} 
		set 
		{
			// 
		}
	}
	
	/// <summary>
	/// raw path of this pair.
	/// </summary>
	IPath m_rawPath;
	
	/// <summary>
	/// inversed path of raw path.
	/// </summary>
	IPath m_inversedPath;
}
